package com.easycar.common.manager;

import com.easycar.common.base.MessageEvent;

import org.greenrobot.eventbus.EventBus;

/**
 *
 *
 * Event  Bus  管理具体类  注意  返回数据回调  在当前UI 界面的onMessageEvent 方法中
 * 最好把数据放到UI 线程中
 * @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent messageEvent) {
   eventMessage(messageEvent);
};
 */

public class EventBusManager<T> {

    private static  EventBusManager  sManager=new EventBusManager();

    private EventBusManager(){

    }

    public  static  EventBusManager   getInstance(){

        return sManager;
    }

    public void  register(T  t){
        EventBus.getDefault().register(t);

    }

    public  <T> void  unRegister(T  t){
        EventBus.getDefault().unregister(t);
    }

    public <E>  void  post(MessageEvent<E> event){
        EventBus.getDefault().post(event);
    }

    /**
     *
     * @param event
     * @param <E>
     */
     public <E> void  cancel(MessageEvent<E> event){
         EventBus.getDefault().cancelEventDelivery(event);
     }





}
